package app.fitness.simplefragment;

import java.util.Calendar;

import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.chart.BarChart.Type;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.model.XYSeries;
import org.achartengine.renderer.SimpleSeriesRenderer;
import org.achartengine.renderer.XYMultipleSeriesRenderer;

import utils.Utils;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.Paint.Align;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;
import app.fitness.fragment.DashBoardFragment;

import com.razerzone.android.fitness.R;

import controller.GetSleepData;
import define.Key;
import define.SleepData;

public class DashBoardSleepSimpleFragment extends Fragment {

	/**
	 * Data section
	 */
	private static String[] Y_LABELS = null;

	/**
	 * String section
	 */

	/**
	 * View section
	 */
	private static GraphicalView mChartView;
	private static LinearLayout mLlGraph;
	public static LinearLayout mLlTimeDayMonthMonths;
	private static TextView mTvActivity;
	private static TextView mTvCurrentHoursValue;
	public static TextView mTvFirstDay;
	private static TextView mTvGoalHoursValue;
	public static TextView mTvLastDay;
	public static TextView mTvMiddleDay;

	/**
	 * The others section
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		Y_LABELS = new String[] { getString(R.string.hrs_3),
				getString(R.string.hrs_6), getString(R.string.hrs_9),
				getString(R.string.hrs_12) };
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		/**
		 * Set Orientation for page
		 */
		getActivity().setRequestedOrientation(
				ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);

		View v = null;
		if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
			v = inflater.inflate(R.layout.simple_fragment_dashboard_sleep,
					container, false);

			initialVariables(v);
		}
		return v;
	}

	@Override
	public void onViewStateRestored(Bundle savedInstanceState) {
		super.onViewStateRestored(savedInstanceState);

		showDataOnPage(getActivity());
	}

	/**
	 * Initialize methods
	 */
	private void initialVariables(View v) {
		mLlGraph = (LinearLayout) v
				.findViewById(R.id.ll_graph_in_simple_fragment_dashboard_sleep);
		mLlTimeDayMonthMonths = (LinearLayout) v
				.findViewById(R.id.ll_time_day_month_months_in_simple_fragment_dashboard_sleep);
		mTvActivity = (TextView) v
				.findViewById(R.id.tv_activity_in_simple_fragment_dashboard_sleep);
		mTvCurrentHoursValue = (TextView) v
				.findViewById(R.id.tv_current_hours_value_in_simple_fragment_dashboard_sleep);
		mTvFirstDay = (TextView) v
				.findViewById(R.id.tv_first_day_in_simple_fragment_dashboard_sleep);
		mTvGoalHoursValue = (TextView) v
				.findViewById(R.id.tv_goal_hours_value_in_simple_fragment_dashboard_sleep);
		mTvLastDay = (TextView) v
				.findViewById(R.id.tv_last_day_in_simple_fragment_dashboard_sleep);
		mTvMiddleDay = (TextView) v
				.findViewById(R.id.tv_middle_day_in_simple_fragment_dashboard_sleep);
	}

	/**
	 * Basic methods
	 */

	private static void drawChartView(Context context) {
		if (mChartView == null) {
			/**
			 * Initial Chart View
			 */
			mChartView = getBarChart(context);

			/**
			 * Add Chart View
			 */
			mLlGraph.addView(mChartView, new LayoutParams(
					android.view.ViewGroup.LayoutParams.MATCH_PARENT,
					android.view.ViewGroup.LayoutParams.MATCH_PARENT));
		} else {
			/**
			 * Remove Chart View before update Chart View again
			 */
			Utils.removeViewParent(mChartView);

			/**
			 * Reset Chart View
			 */
			mChartView = null;

			/**
			 * Initial Chart View
			 */
			mChartView = getBarChart(context);

			/**
			 * Add Chart View
			 */
			mLlGraph.addView(mChartView, new LayoutParams(
					android.view.ViewGroup.LayoutParams.MATCH_PARENT,
					android.view.ViewGroup.LayoutParams.MATCH_PARENT));
		}
	}

	private static GraphicalView getBarChart(Context context) {
		XYMultipleSeriesRenderer barChartRenderer = getBarChartRenderer(context);
		GraphicalView mGp = ChartFactory.getBarChartView(context,
				getBarDataset(context), barChartRenderer, Type.DEFAULT);
		return mGp;
	}

	private static XYMultipleSeriesDataset getBarDataset(Context context)
			throws OutOfMemoryError {
		XYMultipleSeriesDataset barChartDataset = new XYMultipleSeriesDataset();
		// Creating an XYSeries for Deep Sleep
		XYSeries mXYSeriesDeepSleep = new XYSeries("");
		// Creating an XYSeries for Light Sleep
		XYSeries mXYSeriesLightSleep = new XYSeries("");

		int[] x_sleep = null;
		switch (DashBoardFragment.singleTon.getCurrentTimePicker()) {
		case Key.KEY_1_MONTH:
			Calendar mCalendar = Calendar.getInstance(); // Current time
			mCalendar.set(Calendar.MONTH,
					DashBoardFragment.singleTon.getCurrentMonthIndex(context));
			int max_days_of_month = mCalendar
					.getActualMaximum(Calendar.DAY_OF_MONTH);

			switch (max_days_of_month) {
			case 28:
				x_sleep = new int[max_days_of_month * 2 + 52];
				break;
			case 29:
				x_sleep = new int[max_days_of_month * 2 + 58];
				break;
			case 30:
				x_sleep = new int[max_days_of_month * 2 + 64];
				break;
			case 31:
				x_sleep = new int[max_days_of_month * 2 + 70];
				break;
			default:
				break;
			}

			getChartValueMonth(x_sleep, mXYSeriesDeepSleep, mXYSeriesLightSleep);
			break;
		case Key.KEY_3_MONTHS:
			x_sleep = new int[28];
			getChartValueMonths(x_sleep, mXYSeriesDeepSleep,
					mXYSeriesLightSleep);
			break;
		case Key.KEY_DAILY:
			x_sleep = new int[1440];
			getChartValueDaily(context, x_sleep, mXYSeriesDeepSleep,
					mXYSeriesLightSleep);
			break;
		case Key.KEY_WEEKLY:
			x_sleep = new int[45];
			getChartValueWeek(x_sleep, mXYSeriesDeepSleep, mXYSeriesLightSleep);
			break;
		case Key.KEY_YEARLY:
			x_sleep = new int[72];
			getChartValueYear(x_sleep, mXYSeriesDeepSleep, mXYSeriesLightSleep);
			break;
		default:
			break;
		}

		/**
		 * Draw column on the chart
		 */
		barChartDataset.addSeries(mXYSeriesDeepSleep);
		barChartDataset.addSeries(mXYSeriesLightSleep);

		return barChartDataset;
	}

	private static XYMultipleSeriesRenderer getBarChartRenderer(Context context) {
		int[] colors = new int[] {
				context.getResources().getColor(R.color.green_deep_sleep),
				context.getResources().getColor(R.color.green_light_sleep),
				context.getResources().getColor(R.color.grey_content) };

		XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();

		renderer.setAntialiasing(true);
		renderer.setAxesColor(Color.BLACK);
		renderer.setGridColor(Color.BLACK);
		renderer.setLabelsTextSize(25);
		renderer.setMarginsColor(Color.argb(0x00, 0x01, 0x01, 0x01));
		renderer.setPanEnabled(false);
		renderer.setShowGridX(true);
		renderer.setShowAxes(false);
		renderer.setShowLegend(false);
		renderer.setXLabels(0);
		renderer.setXLabelsColor(colors[2]);
		renderer.setYLabels(0);
		renderer.setYLabelsColor(0, colors[2]);
		renderer.setZoomEnabled(false, false);
		renderer.setXLabelsAlign(Align.CENTER);
		renderer.setYLabelsAlign(Align.LEFT);

		// Add X labels
		switch (DashBoardFragment.singleTon.getCurrentTimePicker()) {
		case Key.KEY_1_MONTH:
			Calendar mCalendar = Calendar.getInstance(); // Current time
			mCalendar.set(Calendar.MONTH,
					DashBoardFragment.singleTon.getCurrentMonthIndex(context));
			int max_days_of_month = mCalendar
					.getActualMaximum(Calendar.DAY_OF_MONTH);

			// Set margin
			renderer.setBarSpacing(4f);
			renderer.setXAxisMin(-7);

			// Set value for time line
			renderer.addXTextLabel(3,
					"1 " + DashBoardFragment.singleTon.getCurrentMonth());
			// Set axis
			switch (max_days_of_month) {
			case 28:
				renderer.setXAxisMax(2 * max_days_of_month + 30);

				renderer.addXTextLabel(1.5 * max_days_of_month, "15 "
						+ DashBoardFragment.singleTon.getCurrentMonth());
				renderer.addXTextLabel(
						2 * max_days_of_month + 28,
						max_days_of_month + " "
								+ DashBoardFragment.singleTon.getCurrentMonth());
				break;
			case 29:
				renderer.setXAxisMax(2 * max_days_of_month + 40);

				renderer.addXTextLabel(1.5 * max_days_of_month, "15 "
						+ DashBoardFragment.singleTon.getCurrentMonth());
				renderer.addXTextLabel(
						2 * max_days_of_month + 38,
						max_days_of_month + " "
								+ DashBoardFragment.singleTon.getCurrentMonth());
				break;
			case 30:
				renderer.setXAxisMax(2 * max_days_of_month + 50);

				renderer.addXTextLabel(2 * max_days_of_month, "15 "
						+ DashBoardFragment.singleTon.getCurrentMonth());
				renderer.addXTextLabel(
						2 * max_days_of_month + 47,
						max_days_of_month + " "
								+ DashBoardFragment.singleTon.getCurrentMonth());
				break;
			case 31:
				renderer.setXAxisMax(2 * max_days_of_month + 60);

				renderer.addXTextLabel(2 * max_days_of_month, "15 "
						+ DashBoardFragment.singleTon.getCurrentMonth());
				renderer.addXTextLabel(
						2 * max_days_of_month + 57,
						max_days_of_month + " "
								+ DashBoardFragment.singleTon.getCurrentMonth());
				break;
			default:
				break;
			}

			renderer.setYAxisMin(0);
			renderer.setYAxisMax(720);

			break;
		case Key.KEY_3_MONTHS:
			// Set margin
			renderer.setBarSpacing(1f);

			// Set axis
			renderer.setXAxisMin(0);
			renderer.setXAxisMax(23);
			renderer.setYAxisMin(0);

			// Set value for time line
			renderer.addXTextLabel(2.5,
					DashBoardFragment.singleTon.getPrevious3Months() + "");
			renderer.addXTextLabel(11.5, Utils.getCorrectMonth(context, null,
					DashBoardFragment.singleTon.getCurrentMiddleMonthIndex()));
			renderer.addXTextLabel(20.5,
					DashBoardFragment.singleTon.getNext3Months());
			break;
		case Key.KEY_DAILY:
			// Set margin
			renderer.setBarSpacing(0f);

			/**
			 * Need check current orientation to set Bar width exactly
			 */
			if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
				/**
				 * Portrait orientation
				 */
				renderer.setBarWidth(1f);
			} else {
				/**
				 * Landscape orientation
				 */
				renderer.setBarWidth(3f);
			}

			renderer.setXLabels(0);
			// Set axis
			renderer.setXAxisMin(0);
			renderer.setXAxisMax(1440);
			renderer.setYAxisMin(0);
			renderer.setYAxisMax(1);

			// renderer.addXTextLabel(0, context.getString(R.string.AM12));
			// renderer.addXTextLabel(700, context.getString(R.string.PM));
			// renderer.addXTextLabel(1339, context.getString(R.string.AM12));
			break;
		case Key.KEY_WEEKLY:
			// Set margin
			renderer.setBarSpacing(1f);

			// Set axis
			renderer.setXAxisMin(-2);
			renderer.setXAxisMax(41);
			renderer.setYAxisMin(0);
			renderer.setYAxisMax(720);

			// Set value for time line
			renderer.addXTextLabel(3.5, context.getString(R.string.monday));
			renderer.addXTextLabel(9.5, context.getString(R.string.tuesday));
			renderer.addXTextLabel(15.5, context.getString(R.string.wednesday));
			renderer.addXTextLabel(21.5, context.getString(R.string.thusday));
			renderer.addXTextLabel(27.5, context.getString(R.string.friday));
			renderer.addXTextLabel(33.5, context.getString(R.string.saturday));
			renderer.addXTextLabel(39.5, context.getString(R.string.sunday));
			break;
		case Key.KEY_YEARLY:
			// Set margin
			renderer.setBarSpacing(2f);

			// Set axis
			renderer.setXAxisMin(-5);
			renderer.setXAxisMax(72);
			renderer.setYAxisMin(0);

			// Set value for time line
			renderer.addXTextLabel(0.5, context.getString(R.string.jannuary));
			renderer.addXTextLabel(6.5, context.getString(R.string.february));
			renderer.addXTextLabel(12.5, context.getString(R.string.march));
			renderer.addXTextLabel(18.5, context.getString(R.string.april));
			renderer.addXTextLabel(24.5, context.getString(R.string.may));
			renderer.addXTextLabel(30.5, context.getString(R.string.june));
			renderer.addXTextLabel(36.5, context.getString(R.string.july));
			renderer.addXTextLabel(42.5, context.getString(R.string.august));
			renderer.addXTextLabel(48.5, context.getString(R.string.september));
			renderer.addXTextLabel(54.5, context.getString(R.string.october));
			renderer.addXTextLabel(60.5, context.getString(R.string.november));
			renderer.addXTextLabel(66.5, context.getString(R.string.december));
			break;
		default:
			break;
		}

		// Add Y labels
		switch (DashBoardFragment.singleTon.getCurrentTimePicker()) {
		case Key.KEY_DAILY:
			break;
		case Key.KEY_3_MONTHS:
			break;
		case Key.KEY_YEARLY:
			break;
		default:
			renderer.setLabelsColor(context.getResources().getColor(
					R.color.grey));
			renderer.setLabelsTextSize(25);
			renderer.setYAxisAlign(Align.LEFT, 0);
			renderer.addYTextLabel(180, Y_LABELS[0]);
			renderer.addYTextLabel(360, Y_LABELS[1]);
			renderer.addYTextLabel(540, Y_LABELS[2]);
			renderer.addYTextLabel(720, Y_LABELS[3]);
			break;
		}

		// Columns in chart
		SimpleSeriesRenderer r = new SimpleSeriesRenderer();
		r.setColor(colors[0]);
		renderer.addSeriesRenderer(r);

		r = new SimpleSeriesRenderer();
		r.setColor(colors[1]);
		renderer.addSeriesRenderer(r);

		return renderer;
	}

	private static void getChartValueDaily(Context context, int[] x_sleep,
			XYSeries mXYSeriesDeepSleep, XYSeries mXYSeriesLightSleep) {
		/**
		 * Get current day to compare
		 */
		String CURRENT_DAY = DashBoardFragment.singleTon.getCurrentDate();
		int today[] = new int[2];

		DashBoardFragment.mTvDate.setText(CURRENT_DAY);
		DashBoardFragment.singleTon.setCurrentDate(CURRENT_DAY);

		String[] current_day = CURRENT_DAY.split(" ");
		if (CURRENT_DAY.contains(context.getString(R.string.today))) {
			today[0] = Integer.valueOf(current_day[1]);
			today[1] = Utils.getCorrectIndexMonth(context, current_day[2]);
		} else {
			today[0] = Integer.valueOf(current_day[0]);
			today[1] = Utils.getCorrectIndexMonth(context, current_day[1]);
		}
		/**
		 * Check language in System Settings to get today
		 */
		// switch (Utils.checkLanguageInSettings()) {
		// case Language.CHINESE:
		// if (CURRENT_DAY.contains(context.getString(R.string.today))) {
		// today = Integer.valueOf(CURRENT_DAY.trim().substring(3, 5));
		// } else {
		// today = Integer.valueOf(CURRENT_DAY.trim().substring(0, 2));
		// }
		// break;
		// case Language.ENGLISH:
		// if (CURRENT_DAY.contains(context.getString(R.string.today))) {
		// today = Integer.valueOf(CURRENT_DAY.substring(6, 8));
		// } else {
		// today = Integer.valueOf(CURRENT_DAY.substring(0, 2));
		// }
		// break;
		// }

		/**
		 * Begin draw on chart
		 */
		int record_end_time = 0;
		int index_increased_in_size_today = 0;
		for (Long recordStartTime : SleepData.mLlSdRecordStart) {
			// Start time
			Calendar mCalendarStart = Calendar.getInstance();
			mCalendarStart.setTimeInMillis(recordStartTime * 1000);

			// get Hours and Minutes of start time
			int hours_start_time = mCalendarStart.get(Calendar.HOUR_OF_DAY);
			int minutes_start_time = mCalendarStart.get(Calendar.MINUTE);

			// End time
			Calendar mCalendarEnd = Calendar.getInstance();
			mCalendarEnd.setTimeInMillis(SleepData.mLlSdRecordEnd
					.get(record_end_time) * 1000);
			record_end_time++;
			if ((mCalendarStart.get(Calendar.DAY_OF_MONTH) < today[0] & mCalendarStart
					.get(Calendar.MONTH) == today[1])
					| (mCalendarStart.get(Calendar.DAY_OF_MONTH) > today[0] & mCalendarStart
							.get(Calendar.MONTH) < today[1])) {
				/**
				 * If start day [i] < today, draw from end time[0] to 0 AM
				 */
				/**
				 * If data returned is different day, used today, so need draw
				 * from 0:00 AM
				 */
				// This loop will run from Deep Sleep length
				// to light sleep length
				// get Hours and Minutes of start time
				int hours_end_time = mCalendarEnd.get(Calendar.HOUR_OF_DAY);
				int minutes_end_time = mCalendarEnd.get(Calendar.MINUTE);

				// Get index to show on chart
				int index_end_time = hours_end_time * 60 + minutes_end_time;
				/**
				 * Get index size
				 */
				int index_size = 0;
				for (int i = 0; i < GetSleepData.size_starttime_today.length; i++) {
					if (GetSleepData.size_starttime_today[i] > 0) {
						index_size += GetSleepData.size_starttime_today[i];
					}
				}

				/**
				 * Begin get sleep time
				 */
				for (int i = index_size - 1; i > 0; i--) {
					if (index_end_time < 0) {
						break;
					}

					if (GetSleepData.sleep_daily_value[index_end_time] == true) {
						// Light Sleep
						x_sleep[index_end_time] = 1;

						mXYSeriesLightSleep.add(index_end_time,
								x_sleep[index_end_time]);
					} else {
						// Deep Sleep
						x_sleep[index_end_time] = 1;

						mXYSeriesDeepSleep.add(index_end_time,
								x_sleep[index_end_time]);
					}

					index_end_time--;
				}
				index_increased_in_size_today++;
			} else if ((today[0] < mCalendarEnd.get(Calendar.DAY_OF_MONTH) & mCalendarEnd
					.get(Calendar.MONTH) == today[1])
					| (today[0] > mCalendarEnd.get(Calendar.DAY_OF_MONTH) & mCalendarEnd
							.get(Calendar.MONTH) > today[1])) {
				// Get index to show on chart
				int index_start_time = hours_start_time * 60
						+ minutes_start_time;

				/**
				 * If today < end time[i], draw from start time[i] to 0 AM
				 */
				/**
				 * Get index size
				 */
				int index_size = 0;
				for (int i = 0; i < GetSleepData.size_today_endtime.length; i++) {
					if (GetSleepData.size_today_endtime[i] > 0) {
						index_size += GetSleepData.size_today_endtime[i];
					}
				}

				/**
				 * Begin get sleep time
				 */
				for (int i = 0; i < index_size; i++) {
					if (index_start_time == x_sleep.length) {
						break;
					}

					if (GetSleepData.sleep_daily_value[index_start_time] == true) {
						// Light Sleep
						x_sleep[index_start_time] = 1;

						mXYSeriesLightSleep.add(index_start_time,
								x_sleep[index_start_time]);
					} else {
						// Deep Sleep
						x_sleep[index_start_time] = 1;

						mXYSeriesDeepSleep.add(index_start_time,
								x_sleep[index_start_time]);
					}

					index_start_time++;
				}
				index_increased_in_size_today++;
			} else if (mCalendarStart.get(Calendar.DAY_OF_MONTH) == today[0]
					& mCalendarStart.get(Calendar.MONTH) == today[1]) {
				/**
				 * If start day [i] = today, draw from start time[i] to end
				 * time[i]
				 */
				/**
				 * If data returned is same day, so need draw from specify hours
				 */
				/**
				 * Index of chart view
				 */
				// Get index to show on chart
				int index_start_time = hours_start_time * 60
						+ minutes_start_time;

				for (int i = 0; i < GetSleepData.size_today[index_increased_in_size_today]; i++) {
					if (GetSleepData.sleep_daily_value[index_start_time] == true) {
						// Light Sleep
						x_sleep[index_start_time] = 1;
						mXYSeriesLightSleep.add(index_start_time,
								x_sleep[index_start_time]);
					} else {
						// Deep Sleep
						x_sleep[index_start_time] = 1;
						mXYSeriesDeepSleep.add(index_start_time,
								x_sleep[index_start_time]);
					}

					index_start_time++;
				}
				index_increased_in_size_today++;
			}
		}
	}

	private static void getChartValueMonth(int[] x_sleep,
			XYSeries mXYSeriesDeepSleep, XYSeries mXYSeriesLightSleep) {
		int deep_sleep = 0;
		int light_sleep = 0;

		for (int i = 0; i < x_sleep.length; i += 4) {
			if ((i > x_sleep.length - 1)
					| (deep_sleep > SleepData.MONTH_DEEP_SLEEP.length - 1)) {
				break;
			}

			x_sleep[i] = SleepData.MONTH_DEEP_SLEEP[deep_sleep];
			x_sleep[i + 1] = SleepData.MONTH_LIGHT_SLEEP[light_sleep];
			x_sleep[i + 2] = 0;
			x_sleep[i + 3] = 0;

			mXYSeriesDeepSleep.add(i, x_sleep[i]);
			mXYSeriesLightSleep.add(i + 1, x_sleep[i + 1]);

			deep_sleep++;
			light_sleep++;
		}
	}

	private static void getChartValueMonths(int[] x_sleep,
			XYSeries mXYSeriesDeepSleep, XYSeries mXYSeriesLightSleep) {
		int deep_sleep = 0;
		int light_sleep = 0;

		for (int i = 2; i < x_sleep.length; i += 9) {
			x_sleep[i] = SleepData.MONTHS_DEEP_SLEEP[deep_sleep];
			x_sleep[i + 1] = SleepData.MONTHS_LIGHT_SLEEP[light_sleep];

			for (int j = 2; j < 7; j++) {
				x_sleep[i + j] = 0;
			}

			mXYSeriesDeepSleep.add(i, x_sleep[i]);
			mXYSeriesLightSleep.add(i + 1, x_sleep[i + 1]);

			deep_sleep++;
			light_sleep++;
		}
	}

	private static void getChartValueWeek(int[] x_sleep,
			XYSeries mXYSeriesDeepSleep, XYSeries mXYSeriesLightSleep) {
		int deep_sleep = 0;
		int light_sleep = 0;

		for (int i = 3; i < x_sleep.length; i += 6) {
			x_sleep[i] = SleepData.WEEK_DEEP_SLEEP[deep_sleep];
			x_sleep[i + 1] = SleepData.WEEK_LIGHT_SLEEP[light_sleep];

			for (int j = 2; j < 6; j++) {
				x_sleep[i + j] = 0;
			}

			mXYSeriesDeepSleep.add(i, x_sleep[i]);
			mXYSeriesLightSleep.add(i + 1, x_sleep[i + 1]);

			deep_sleep++;
			light_sleep++;
		}
	}

	private static void getChartValueYear(int[] x_sleep,
			XYSeries mXYSeriesDeepSleep, XYSeries mXYSeriesLightSleep) {
		int deep_sleep = 0;
		int light_sleep = 0;
		for (int i = 0; i < x_sleep.length; i += 6) {
			x_sleep[i] = SleepData.YEAR_DEEP_SLEEP[deep_sleep];
			x_sleep[i + 1] = SleepData.YEAR_LIGHT_SLEEP[light_sleep];

			for (int j = 2; j < 6; j++) {
				x_sleep[i + j] = 0;
			}

			mXYSeriesDeepSleep.add(i, x_sleep[i]);
			mXYSeriesLightSleep.add(i + 1, x_sleep[i + 1]);

			deep_sleep++;
			light_sleep++;
		}
	}

	public static void showDataOnPage(Context context) {
		// Set activity
		mTvActivity.setText(context.getString(R.string.sleep_));

		/**
		 * Check deep sleep + light sleep first before calculate total sleep
		 */
		int sleep_hours = Integer.valueOf(DashBoardFragment.singleTon
				.getDeepSleepHours())
				+ Integer.valueOf(DashBoardFragment.singleTon
						.getLightSleepHours());
		int sleep_minutes = Integer.valueOf(DashBoardFragment.singleTon
				.getDeepSleepMinutes())
				+ Integer.valueOf(DashBoardFragment.singleTon
						.getLightSleepMinutes());

		// Save into single ton way
		DashBoardFragment.singleTon.setTotalSleepHours("" + sleep_hours);
		DashBoardFragment.singleTon.setTotalSleepMinutes("" + sleep_minutes);

		/**
		 * Correct the time
		 */
		mTvCurrentHoursValue
				.setText(Utils.getCorrectHours(Integer.valueOf(sleep_hours),
						Integer.valueOf(sleep_minutes))[0]
						+ " "
						+ context.getString(R.string.hrs)
						+ " "
						+ Utils.getCorrectHours(Integer.valueOf(sleep_hours),
								Integer.valueOf(sleep_minutes))[1]
						+ " "
						+ context.getString(R.string.mins) + " ");
		// Set goal
		mTvGoalHoursValue.setText(Utils
				.showIntergerFormat(DashBoardFragment.singleTon.getSleepGoal()
						.replace(",", "")));

		drawChartView(context);
		/**
		 * Check current time picker to decide show which time line below chart
		 */
		DashBoardFragment.showTimeLine(context);
	}
}
